local map = vim.keymap.set

-- define common options
local opts = {
    noremap = true, -- non-recursive
    silent = true,  -- do not show message
}

-- map("n", ";", ":", { desc = "CMD enter command mode" })
map("i", "jk", "<ESC>")

-- map({ "n", "i", "v" }, "<C-s>", "<cmd> w <cr>")

-----------------
-- Normal mode --
-----------------

-- Resize with arrows
-- delta: 2 lines
-- map('n', '<C-Up>', ':resize -2<CR>', opts)
-- map('n', '<C-Down>', ':resize +2<CR>', opts)
-- map('n', '<C-Left>', ':vertical resize -2<CR>', opts)
-- map('n', '<C-Right>', ':vertical resize +2<CR>', opts)

-----------------
-- Visual mode --
-----------------

-- Hint: start visual mode with the same area as the previous area and the same mode
-- map('v', '<', '<gv', opts)
-- map('v', '>', '>gv', opts)



--- 以下拷贝自 nvchad.mappings
map("i", "<C-b>", "<ESC>^i", { desc = "Move Beginning of line" })
map("i", "<C-e>", "<End>", { desc = "Move End of line" })
map("i", "<C-h>", "<Left>", { desc = "Move Left" })
map("i", "<C-l>", "<Right>", { desc = "Move Right" })
map("i", "<C-j>", "<Down>", { desc = "Move Down" })
map("i", "<C-k>", "<Up>", { desc = "Move Up" })

map("n", "<Esc>", "<cmd>noh<CR>", { desc = "General Clear highlights" })

-- map("n", "<C-h>", "<C-w>h", { desc = "Switch Window left" })
-- map("n", "<C-l>", "<C-w>l", { desc = "Switch Window right" })
-- map("n", "<C-j>", "<C-w>j", { desc = "Switch Window down" })
-- map("n", "<C-k>", "<C-w>k", { desc = "Switch Window up" })

-- map("n", "<C-s>", "<cmd>w<CR>", { desc = "File Save" })
-- map("n", "<C-c>", "<cmd>%y+<CR>", { desc = "File Copy whole" })

-- map("n", "[d", vim.diagnostic.goto_prev, { desc = "Lsp prev diagnostic" })
-- map("n", "]d", vim.diagnostic.goto_next, { desc = "Lsp next diagnostic" })


-- nvimtree
-- map("n", "<C-n>", "<cmd>NvimTreeToggle<CR>", { desc = "Nvimtree Toggle window" })

-- telescope
-- map("n", "<leader>fw", "<cmd>Telescope live_grep<CR>", { desc = "Telescope Live grep" })
-- map("n", "<leader>fb", "<cmd>Telescope buffers<CR>", { desc = "Telescope Find buffers" })
-- map("n", "<leader>fh", "<cmd>Telescope help_tags<CR>", { desc = "Telescope Help page" })
--
-- map("n", "<leader>fo", "<cmd>Telescope oldfiles<CR>", { desc = "Telescope Find oldfiles" })
-- map("n", "<leader>fz", "<cmd>Telescope current_buffer_fuzzy_find<CR>", { desc = "Telescope Find in current buffer" })
-- map("n", "<leader>cm", "<cmd>Telescope git_commits<CR>", { desc = "Telescope Git commits" })
-- map("n", "<leader>gt", "<cmd>Telescope git_status<CR>", { desc = "Telescope Git status" })
-- map("n", "<leader>ff", "<cmd>Telescope find_files<cr>", { desc = "Telescope Find files" })

-- terminal
local term = require("nvchad.term")
local terminal_horizon_split = function()
    term.new { pos = "sp", size = 0.3 }
end
local terminal_vertical_split = function()
    term.new { pos = "vsp", size = 0.3 }
end
map("t", "<C-x>", "<C-\\><C-N>", { desc = "Terminal Escape terminal mode" })
map("n", "<leader>t", "", { desc = "terminal" })
map("n", "<leader>tp", "<cmd>Telescope terms<CR>", { desc = "Telescope Pick hidden term" })
map("n", "<leader>th", terminal_horizon_split, { desc = "Terminal New horizontal term" })
map("n", "<leader>tv", terminal_vertical_split, { desc = "Terminal New vertical window" })

map(
    "n",
    "<leader>fa",
    "<cmd>Telescope find_files follow=true no_ignore=true hidden=true<CR>",
    { desc = "Telescope Find all files" }
)

